Blocks
Blocks '''are used to create code in the Scratch programming language. The blocks connect to each other as in a jigsaw puzzle, each with a different function or value. They are divided into 8 types: Motion, Looks, Sound, Pen, Control, Sensing, Operators and Variables. Types of blocks There are three different kind of blocks in Scratch: Hats, Stack Blocks, and Reporters. Scratch 1.4 Reference Guide *"Hat": The basic block on Scratch - No program can run without this kind of block. All 4 hat blocks can be found on the "Control" section. ** The Hat Blocks activate when a certain event, like a key pressed, or the green flag clicked, happens. It also reacts to Broadcasts. *'''Stack Blocks: Stack blocks that can be stacked on top of each other. Regular stack blocks are typically rectangular in shape, and have a bump at the bottom and a notch at the top (this bump and notch feature allows for the blocks to be stacked on top of each other). Other stack blocks include: **'"C"': These blocks wrap around a group of blocks (hence their name, due to their C shape), making the blocks run forever, or only under certain conditions. The forever and forever-if blocks are special, however, as no blocks can be added to the bottom of them. **'"Fork"': These blocks wrap around blocks just like a C-Stack Block, however, they actually wrap around two groups of blocks. **'"Caps"': These blocks end or "cap the lid to" a script (or the complete project), so no more blocks can be added to the end of the script - this is noted by the fact that they only have a notch at the top, but no bump at the bottom (thus, you cannot stack blocks underneath them). Examples of these include the "Stop Script" block and "Stop All" block. *'Reporters:' 'These blocks are designed to fit into input areas of certain blocks. There are two different types of reporter blocks: **'Boolean: These blocks have a variable value. They can be true or false, and are shaped like a hexagon. Some of the most frequently used booleans are "key ___ pressed?", and "___ = ___". **'Value/Variable': These blocks hold a number or string value, like a score or level. Many of them can also be shown on the project as a "stage monitor", by clicking the checkbox next to them. They have a round shape. Block Categories Motion Blocks The blocks in the Motion category generally change the position or direction of a sprite. By going to extras, and clicking "Show Motor Blocks", you can activate 5 WeDo blocks for the LEGO® Education WeDo™ kit, which can be seen below. Also the motion blocks can be identified by their blue color. * Move () Steps (Stack): Move __ Steps is used when you want a sprite to move a certain number of steps. A negetive number can be used to make the sprite move backwards. All movement done using this block is done to the direction the sprite is heading to. *'Turn () Degrees (Stack)': Turn __ degrees makes a sprite rotate. There are two variants of this block: Clockwise, and counter-clockwise. *'Point In Direction () (Stack)':' '''Makes the sprite point in a specific direction. In the drop-down menu, you can choose from 90 degrees (right), 180 degrees (down), -90 degrees (left), and 0 degrees (up). * 'Point Towards () (Stack): Makes the sprite point towards another sprite. In the drop-down menu, you can choose from another sprite if there is any, or the mouse pointer. *Go to X: () Y: () (Stack):''' '''Makes a sprite go to a specific X and Y position. *Go to ()' '(Stack):''' '''Makes a sprite go to the position of another sprite. Within the drop-down menu, you can choose from another sprite if there is any, or the mouse pointer. *Glide () Secs To X: () Y: ()' '(Stack):''' '''Makes a sprite move smoothly to a specific X and Y position, in a specified amount of seconds. *Change/Set X/Y By/To () (Stack):''' '''Changes/Sets the X or Y postion of a sprite by/to the specified amount. *If On Edge, Bounce (Stack): If the sprite is touching the edge, makes it point at the opposite direction, providing a neat "bounce" effect. *X/Y Position (Reporter):''' '''Its value is the current X or Y position of the sprite. Can be displayed as a stage monitor. *Direction (block) (Reporter): Its value is the direction, in 360º degree format, that the sprite is pointing to. For unknown reasons, Scratch's degrees go from -180 to 180, rather than from 0 to 360, unlike other programming languages. Can be displayed as a stage monitor. :See also, Accessory Blocks for the motor blocks. Looks Blocks The blocks in the Looks category generally effect how a sprite appears on the screen. Also the looks blocks can be identified by their blue-ish purple color. *Switch To Costume () (Stack): Switches the sprite's costume to a specified costume. *Next Costume(Stack): Switches the sprite's costume to the next costume after the current. *Costume# (Reporter): It's the value is the number of the current sprite's costume. Can be displayed as a stage monitor. *Say () (For () Secs) (Stack): The sprite "says" a phrase inside a speech bubble, for a indefinite amount of time, until something stops its effect (such as the stop script block or by putting another think or say block with nothing in the textbox after it). However, a specified amount of seconds can be used in a alternate form of the block. *Think () (For () Secs.) (Stack): The sprite "thinks" a phrase inside a cloud, for a indefinite amount of time, until something stops its effect (such as the stop script block or by putting another think or say block with nothing in the textbox after it). However, a specified amount of seconds can be used in a alternate form of the block. *Change/Set () Effect By/To () (Stack): Changes/Sets a certain graphic effect's value by/to the specified amount. In the drop-down menu, you can choose from color, fisheye, whirl, pixelate, mosaic, brightness, and ghost. *Clear All Graphical Effects (Stack): Resets all graphic effect values to 0. * '''Change/Set Size By/To () (Stack): Change/Sets the sprite's size by/to a specified amount. * Size (block) (Reporter): It's the value is the current size of the sprite. Can be displayed as a stage monitor. *'Show/Hide (Stack)': Makes the sprite visible or invisible, unless its ghost effect is 100 or more. The sprite can't be clicked or used to detect collision if its hidden. *'Go To Front (Stack)': Makes the sprite go to the first layer - in front of all other sprites. *'Go Back () Layers (Stack)': Makes the sprite go back a specific amount of layers. Sound Blocks The blocks in the sounds category generally adds sounds and music to projects. Also the sound blocks can be identified by their red-ish purple color. *'Play Sound ()' (Stack): Makes the sprite play a sound, with the other blocks playing immediatly after. This means if another sound plays when the current sound is still not finished, the current sound will stop, and the next one will play. In the drop-down menu, you can choose from any sounds that are currently available in that sprite. *'Play Sound () Until Done' (Stack): Makes the sprite play a sound, but other blocks in the script do not play until the sound/song is finished. In the drop-down menu, you can choose from any sounds that are currently available in that sprite. *'Stop All Sounds' (Stack): Stops all of the sounds in the project. *'Play Drum () For () Beats' (Stack): Plays the chosen drum sound for the amount of time specified. The amount of time will be affected by the tempo. *'Rest For () Beats' (Stack): Plays one rest of silence for the specified amount of time. The amount of time will be affected by the tempo. *'Play Note () For () Beats' (Stack): Plays a note of the specified pitch, instrument, and time. The amount of time will be affected by the tempo. *'Set Instrument To ()' (Stack): Sets the instrument to the specified instrument. *'Change/Set Volume By/To () (Stack)': Changes/Sets the volume of the sounds following this block by/to the amount specified. *'Volume' (Reporter): It's the volume of the sounds in the program. The volume will also be affected by the computer's volume setting. Can be displayed as a stage monitor. *'Change/Set Tempo By/To ()' (Stack): Changes/Sets the tempo, which is the speed of the music, by/to the amount specified. *'Tempo' (Reporter): It's the tempo, which is the speed of the music. Can be displayed as a stage monitor. Pen Blocks The blocks in the pen category can be used to directly draw onto the stage. Also the pen blocks can be identified by their blue-green-ish color. *'Clear (Stack)': Clears all pen marks and stamps from the stage. *'Pen Down (Stack)': The sprite starts leaving a pen trail. *'Pen Up (Stack)': The sprite stops leaving a pen trail. *'Set Pen Color to () (Pen Dropper) (Stack)': Sets the pen color trail to the selected color. *'Change Pen Color By () (Stack)': Changes the pen color (hue) by the specified value. There are 200 possible color values. *'Set Pen Color to () (Number) (Stack)': Sets the pen color (hue) to the speicified value. There are 200 possible color values. *'Change Pen Shade By () (Stack)': Changes the pen shade (lightness) by the specified value. There are 100 possible shade values. *'Set Pen Shade To () (Stack)': Sets the pen shade (lightness) to the speicified value. There are 100 possible shade values. *'Change Pen Size By () (Stack)': Changes the pen size (thickness) by the specified value. *'Set Pen Size To () (Stack)': Sets the pen size (thickness) to the speicified value. *'Stamp (Stack)': This block stamps the sprite's current costume onto the stage. Control Blocks The blocks in the control category are the basic block scripting commands, they control how the script runs. *'When Flag Clicked (Hat)': When the green flag is clicked, the script below this hat block will be started. *'When () Key Pressed (Hat)': When the specified key is pressed, the script below this hat block will be started. *'When "Sprite" Clicked (Hat)': When this sprite is clicked on, the script below this hat block will be started. *'Wait () Secs (Stack)': Pauses the current script for the specified amount of seconds and then continues. *'Forever (C-Stack)': This block wraps around other blocks and runs them until the script is stopped. *'Repeat () (C-Stack)': This block wraps around other blocks and runs them (10) times. *'Broadcast () (Stack)': This block broadcasts the specified message to all 'when I recieve' hat blocks. *'Broadcast () And Wait (Stack)': This block broadcasts the specified message to all 'when I recieve' hat blocks and waits until their scripts have finished. *'When I Recieve () (Hat)': As soon as the specified message is broadcasted by a [ -] 'or '[ - and wait] block, the script below this hat block will be started. *'Forever If () (C-Stack)': This block wraps around other blocks and runs them as long as the specified condition is true. *'If () (C-Stack)': This block wraps around other blocks and only runs them if specified condition is true. *'If (), Else (Fork-Stack)': This block is divided into two sections that can contain blocks. The blocks in the first section will be run if the specified condition is true, if it's false the other section will be run. *'Wait Until () (Stack)': This block pauses the script until the specified condition is true. *'Repeat Until () ©': This block wraps around other blocks and repeatedly runs them until the specified condition is true. *'Stop Script (Cap-Stack)': Stops the current script. *'Stop All (Cap-Stack)': Stops all running scripts in the project. Sensing Blocks These blocks check or read different values. *'touching [] (Boolean)': Checks if its sprite is touching another sprite, the mouse-pointer, or an edge. *'touching color [ ] (Boolean)': Checks if its sprite is touching a certain color. *'color [ ] is touching [ ] (Boolean)': Checks if a color is touching another. *'ask [] and wait (Command)': Lets the user input a string. When the ask block is run, the sprite will ask what is in the brackets, a text box will appear on the bottom of the stage. After the user inputs something, presses enter or clicks the check mark, the user input will be stored in the (answer) variable. *'answer (Value/Variable)': Stores what the user inputs into the text-box after an ask block has ran. *'mouse x (Reporter)': Contains the current x position of the mouse-pointer. *'mouse y (Reporter)': Contains the current y position of the mouse-pointer. *'mouse down (Boolean)': Checks if the left mouse button is down. *'key [] pressed (Boolean)': Checks if a certain key is pressed. *'distance to [] (Reporter)': Contains the distance of a certain sprite to another sprite or the mouse-pointer. *'reset timer (Stack)': Sets the timer to 0.0. *'timer (Reporter)': Contains the elapsed time from the start of the program or when the timer was last reset. *'[] of [] (Reporter)': Reads the X position, Y position, direction, costume number, size, or volume of a sprite or the Stage. *'loudness (Reporter)': Contains the loudness of the noise made through a speaker. *'loud? (Boolean)': Checks if there is noise being made through a speaker. *'slider sensor value': Reads variables from participants through Mesh. *'sensor pressed (Boolean)': Checks if specific buttons and such are being pressed on a Sensor Board. Operators Blocks (Also called Numbers Blocks in older versions) Operator blocks are used to perform numerical operations and will return the results. *'( ) + ( ) (Value/Variable)': Adds value 1 to value 2 and returns the result. *'( ) - ( ) (Value/Variable)': Subtracts value 1 from value 2 and returns the result. *'( ) * ( ) (Value/Variable)': Multiplies value 1 by value 2 and returns the result. *'( ) / ( ) (Value/Variable)': Divides value 1 by value 2 and returns the result. Note that division by 0 stops the script and highlights this block red. *'pick random ( ) to ( ) (Value/Variable)': Generates and reports a random integer between value 1 and value 2. *'<> < <> (Boolean)': Checks if a value is smaller than the other. *'<> = <> (Boolean)': Checks if a value is equal to another. *'<> > <> (Boolean)': Checks if a value is greater than another. *'<> and <> (Boolean)': Joins two booleans together. *'<> or <> (Boolean)': Joins two booleans together, but they remain seperate. *'not <> (Boolean)': Checks if a boolean is false. *'join [] [] (Value/Variable)': Joins two strings together. *'letter () of [] (Value/Variable)': Reads the specified character of a given string. *'length of [] (Value/Variable)': Gives the character length of a given string. *'() mod () (Value/Variable)': Gives the remainder of the first number divided by the second. *'round () (Value/Variable)': Rounds a given number to the nearest integer. *'[] of () (Value/Variable)': Gives the square root, absolute value, sine, cosine, tangent, arcsine, arccosine, arctangent, natural logarithm, or logarithm of a given number. Variables Blocks Once created, variables can be used to store information and recall it. *'() (Value/Variable)': Contains a value and can recall it. *'set [] to () (Stack)': Sets a variable's value to a given umber. *'change [] by () (Stack)': Changes a variable by a given value. *'show variable [] (Stack)': Shows a hidden variable display. *'hide varible [] (Stack)': Hides a shown variable display. List Blocks Despite being placed in the Variables block palette, List Blocks are color-coded differently than Variables and have their own properties. Lists can store multiple pieces of information at once, including variables. *'add [] to [] (Stack)': Adds an item to a given list, placed at the end. *'delete item () of [] (Stack)': Deletes a given item of a list. *'insert [] at item () of [] (Stack)': Adds an item to a list, placed at a given point. *'replace item () of [] with [] (Stack)': Deletes an item of a list and inserts another in its place. *'item () of [] (Value/Variable)': Reports the content of the listed item of a given list. *'length of [] (Value/Variable)': Reports the item length of a given list. *'[] contains [] (Boolean)': Checks if a given list contains an item with the content of a given string/value. Accessory Blocks Scratch Sensor Board/Pico Board Blocks These blocks are used to interact with the Scratch Board/Picoboard. *'(- sensor value) (Value/Variable)': Used to check the value of the Slider, Light, Sound and Resistance sensors. *''' (Boolean): Used to check if the button is pressed, of if the Resistance sensors are connected. LEGO® Education WeDo™ Kit Blocks These blocks are used to interact with the LEGO WeDo kit. They can be activated on Scratch 1.4 by clicking on the Edit menu, then "Show motor blocks". Motor Blocks *Motor on for () secs (Stack): Turns the motor on for the specified amount of seconds. *Motor on (Stack): Turns the motor on. *Motor off (Stack): Turns the motor off. *Motor power () (Stack): Sets the power of the motor to the specified amount. *Motor direction () (Stack): Sets the direction of the motor to "this way" (clockwise), "that way" (counter-clockwise), or "reverse" (opposite direction). Also, there is one other block which can be used with the LEGO® Education WeDo™ Kit: '''() Sensor Value (Reporter); which can be used with the additional values Tilt and Distance. External Links Scratch Help Screens (examples of blocks) References Category:Blocks